export default class EventBus {
	constructor() {
		this.events = {};
	}
	
	$on(type, fn) {
		this.events = this.events || {};
		this.events[type] = this.events[type] || [];
		this.events[type].push(fn)
	}
	
	$emit(type, data){
		if(this.events[type] && this.events[type].length > 0){
			this.events[type].forEach((fn)=>{
				fn(data);
			})
		}
	}
	
	$off(type){
		if(type){
			this.events[type] = [];	
		}else{
			this.events = {};
		}
	}
}